home *** CD-ROM | disk | FTP | other *** search
/ Programming a Multiplayer FPS in DirectX / Programming a Multiplayer FPS in DirectX (Companion CD).iso / DirectX / dxsdk_oct2004.exe / dxsdk.exe / Samples / Managed / DirectSound / SoundFX / Main.cs next >
Encoding:
Text File  |  2004-09-27  |  79.7 KB  |  1,669 lines

  1. //----------------------------------------------------------------------------
  2. // File: Main.cs
  3. //
  4. // Copyright (c) Microsoft Corp. All rights reserved.
  5. //-----------------------------------------------------------------------------
  6. using System;
  7. using System.Drawing;
  8. using System.Collections;
  9. using System.Windows.Forms;
  10. using Microsoft.DirectX;
  11. using Microsoft.DirectX.DirectSound;
  12. using Buffer = Microsoft.DirectX.DirectSound.Buffer;
  13.  
  14. public class MainForm : Form
  15. {
  16.     #region Control declarations
  17.     private System.Windows.Forms.ListBox listboxEffects;
  18.     private System.Windows.Forms.RadioButton radiobuttonRadioSine;
  19.     private Button buttonOk;
  20.     private GroupBox groupboxFrame;
  21.     private Label labelParamName1;
  22.     private Label labelParamValue1;
  23.     private TrackBar trackbarSlider1;
  24.     private Label labelParamMin1;
  25.     private Label labelParamMax1;
  26.     private Label labelParamName2;
  27.     private Label labelParamValue2;
  28.     private TrackBar trackbarSlider2;
  29.     private Label labelParamMin2;
  30.     private Label labelParamMax2;
  31.     private Label labelParamName3;
  32.     private Label labelParamValue3;
  33.     private TrackBar trackbarSlider3;
  34.     private Label labelParamMin3;
  35.     private Label labelParamMax3;
  36.     private Label labelParamName4;
  37.     private Label labelParamValue4;
  38.     private TrackBar trackbarSlider4;
  39.     private Label labelParamMin4;
  40.     private Label labelParamMax4;
  41.     private Label labelParamName5;
  42.     private Label labelParamValue5;
  43.     private TrackBar trackbarSlider5;
  44.     private Label labelParamMin5;
  45.     private Label labelParamMax5;
  46.     private Label labelParamName6;
  47.     private Label labelParamValue6;
  48.     private TrackBar trackbarSlider6;
  49.     private Label labelParamMin6;
  50.     private Label labelParamMax6;
  51.     private RadioButton radiobuttonTriangle;
  52.     private RadioButton radiobuttonSquare;
  53.     private GroupBox groupboxFrameWaveform;
  54.     private Button buttonOpen;
  55.     private Label labelTextFilename;
  56.     private Label labelStatic2;
  57.     private Label labelTextStatus;
  58.     private CheckBox checkboxLoop;
  59.     private Button buttonPlay;
  60.     private Button buttonStop;
  61.     private Label labelStatic3;
  62.     private GroupBox groupboxFramePhase;
  63.     private Label labelStatic4;
  64.     private RadioButton radiobuttonRadioNeg180;
  65.     private RadioButton radiobuttonRadioNeg90;
  66.     private RadioButton radiobuttonRadioZero;
  67.     private RadioButton radiobuttonRadio90;
  68.     private RadioButton radiobuttonRadio180;
  69.     private System.Windows.Forms.GroupBox groupboxEffects;
  70.     #endregion
  71.  
  72.     private struct EffectInfo
  73.     {
  74.         public EffectDescription description;
  75.         public object EffectSettings;
  76.         public object Effect;
  77.     };
  78.     ArrayList effectDescription = new ArrayList();
  79.     SecondaryBuffer applicationBuffer = null;
  80.     Device applicationDevice = null;
  81.     string fileName = string.Empty;
  82.     string path = string.Empty;
  83.     bool shouldLoop = false;
  84.     private System.Windows.Forms.Button buttonDelete;
  85.     private System.Windows.Forms.Timer timer1;
  86.     private System.ComponentModel.IContainer components;
  87.     private System.Windows.Forms.ComboBox comboEffects;
  88.     private int currentIndex = 0;
  89.     private bool isIgnoringSettings = false;
  90.  
  91.     public static void Main()
  92.     {
  93.         try
  94.         {
  95.             using (MainForm f = new MainForm())
  96.             {
  97.                 Application.Run(f);
  98.             }
  99.         }
  100.         catch{}
  101.     }    
  102.     public MainForm()
  103.     {
  104.         InitializeComponent();
  105.         InitDirectSound();
  106.         ClearUI(true);
  107.     }
  108.     #region InitializeComponent code
  109.     private void InitializeComponent()
  110.     {
  111.         this.components = new System.ComponentModel.Container();
  112.         this.buttonOk = new System.Windows.Forms.Button();
  113.         this.groupboxFrame = new System.Windows.Forms.GroupBox();
  114.         this.labelParamName1 = new System.Windows.Forms.Label();
  115.         this.labelParamValue1 = new System.Windows.Forms.Label();
  116.         this.trackbarSlider1 = new System.Windows.Forms.TrackBar();
  117.         this.labelParamMin1 = new System.Windows.Forms.Label();
  118.         this.labelParamMax1 = new System.Windows.Forms.Label();
  119.         this.labelParamName2 = new System.Windows.Forms.Label();
  120.         this.labelParamValue2 = new System.Windows.Forms.Label();
  121.         this.trackbarSlider2 = new System.Windows.Forms.TrackBar();
  122.         this.labelParamMin2 = new System.Windows.Forms.Label();
  123.         this.labelParamMax2 = new System.Windows.Forms.Label();
  124.         this.labelParamName3 = new System.Windows.Forms.Label();
  125.         this.labelParamValue3 = new System.Windows.Forms.Label();
  126.         this.trackbarSlider3 = new System.Windows.Forms.TrackBar();
  127.         this.labelParamMin3 = new System.Windows.Forms.Label();
  128.         this.labelParamMax3 = new System.Windows.Forms.Label();
  129.         this.labelParamName4 = new System.Windows.Forms.Label();
  130.         this.labelParamValue4 = new System.Windows.Forms.Label();
  131.         this.trackbarSlider4 = new System.Windows.Forms.TrackBar();
  132.         this.labelParamMin4 = new System.Windows.Forms.Label();
  133.         this.labelParamMax4 = new System.Windows.Forms.Label();
  134.         this.labelParamName5 = new System.Windows.Forms.Label();
  135.         this.labelParamValue5 = new System.Windows.Forms.Label();
  136.         this.trackbarSlider5 = new System.Windows.Forms.TrackBar();
  137.         this.labelParamMin5 = new System.Windows.Forms.Label();
  138.         this.labelParamMax5 = new System.Windows.Forms.Label();
  139.         this.labelParamName6 = new System.Windows.Forms.Label();
  140.         this.labelParamValue6 = new System.Windows.Forms.Label();
  141.         this.trackbarSlider6 = new System.Windows.Forms.TrackBar();
  142.         this.labelParamMin6 = new System.Windows.Forms.Label();
  143.         this.labelParamMax6 = new System.Windows.Forms.Label();
  144.         this.radiobuttonTriangle = new System.Windows.Forms.RadioButton();
  145.         this.radiobuttonSquare = new System.Windows.Forms.RadioButton();
  146.         this.radiobuttonRadioSine = new System.Windows.Forms.RadioButton();
  147.         this.groupboxFrameWaveform = new System.Windows.Forms.GroupBox();
  148.         this.buttonOpen = new System.Windows.Forms.Button();
  149.         this.labelTextFilename = new System.Windows.Forms.Label();
  150.         this.labelStatic2 = new System.Windows.Forms.Label();
  151.         this.labelTextStatus = new System.Windows.Forms.Label();
  152.         this.checkboxLoop = new System.Windows.Forms.CheckBox();
  153.         this.buttonPlay = new System.Windows.Forms.Button();
  154.         this.buttonStop = new System.Windows.Forms.Button();
  155.         this.labelStatic3 = new System.Windows.Forms.Label();
  156.         this.labelStatic4 = new System.Windows.Forms.Label();
  157.         this.radiobuttonRadioNeg180 = new System.Windows.Forms.RadioButton();
  158.         this.radiobuttonRadioNeg90 = new System.Windows.Forms.RadioButton();
  159.         this.radiobuttonRadioZero = new System.Windows.Forms.RadioButton();
  160.         this.radiobuttonRadio90 = new System.Windows.Forms.RadioButton();
  161.         this.radiobuttonRadio180 = new System.Windows.Forms.RadioButton();
  162.         this.groupboxFramePhase = new System.Windows.Forms.GroupBox();
  163.         this.groupboxEffects = new System.Windows.Forms.GroupBox();
  164.         this.buttonDelete = new System.Windows.Forms.Button();
  165.         this.listboxEffects = new System.Windows.Forms.ListBox();
  166.         this.comboEffects = new System.Windows.Forms.ComboBox();
  167.         this.timer1 = new System.Windows.Forms.Timer(this.components);
  168.         ((System.ComponentModel.ISupportInitialize)(this.trackbarSlider1)).BeginInit();
  169.         ((System.ComponentModel.ISupportInitialize)(this.trackbarSlider2)).BeginInit();
  170.         ((System.ComponentModel.ISupportInitialize)(this.trackbarSlider3)).BeginInit();
  171.         ((System.ComponentModel.ISupportInitialize)(this.trackbarSlider4)).BeginInit();
  172.         ((System.ComponentModel.ISupportInitialize)(this.trackbarSlider5)).BeginInit();
  173.         ((System.ComponentModel.ISupportInitialize)(this.trackbarSlider6)).BeginInit();
  174.         this.groupboxFrameWaveform.SuspendLayout();
  175.         this.groupboxFramePhase.SuspendLayout();
  176.         this.groupboxEffects.SuspendLayout();
  177.         this.SuspendLayout();
  178.         // 
  179.         // buttonOk
  180.         // 
  181.         this.buttonOk.Location = new System.Drawing.Point(87, 432);
  182.         this.buttonOk.Name = "buttonOk";
  183.         this.buttonOk.Size = new System.Drawing.Size(67, 23);
  184.         this.buttonOk.TabIndex = 0;
  185.         this.buttonOk.Text = "E&xit";
  186.         this.buttonOk.Click += new System.EventHandler(this.buttonOk_Click);
  187.         // 
  188.         // groupboxFrame
  189.         // 
  190.         this.groupboxFrame.Location = new System.Drawing.Point(165, 76);
  191.         this.groupboxFrame.Name = "groupboxFrame";
  192.         this.groupboxFrame.Size = new System.Drawing.Size(525, 380);
  193.         this.groupboxFrame.TabIndex = 1;
  194.         this.groupboxFrame.TabStop = false;
  195.         this.groupboxFrame.Text = "Parameters";
  196.         // 
  197.         // labelParamName1
  198.         // 
  199.         this.labelParamName1.Location = new System.Drawing.Point(169, 112);
  200.         this.labelParamName1.Name = "labelParamName1";
  201.         this.labelParamName1.Size = new System.Drawing.Size(117, 13);
  202.         this.labelParamName1.TabIndex = 2;
  203.         this.labelParamName1.TextAlign = System.Drawing.ContentAlignment.TopRight;
  204.         // 
  205.         // labelParamValue1
  206.         // 
  207.         this.labelParamValue1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
  208.         this.labelParamValue1.Location = new System.Drawing.Point(294, 112);
  209.         this.labelParamValue1.Name = "labelParamValue1";
  210.         this.labelParamValue1.Size = new System.Drawing.Size(67, 16);
  211.         this.labelParamValue1.TabIndex = 3;
  212.         this.labelParamValue1.Text = "Value";
  213.         this.labelParamValue1.TextAlign = System.Drawing.ContentAlignment.TopCenter;
  214.         // 
  215.         // trackbarSlider1
  216.         // 
  217.         this.trackbarSlider1.Location = new System.Drawing.Point(426, 112);
  218.         this.trackbarSlider1.Name = "trackbarSlider1";
  219.         this.trackbarSlider1.Size = new System.Drawing.Size(195, 45);
  220.         this.trackbarSlider1.TabIndex = 4;
  221.         this.trackbarSlider1.Text = "Slider1";
  222.         this.trackbarSlider1.TickStyle = System.Windows.Forms.TickStyle.None;
  223.         this.trackbarSlider1.Scroll += new System.EventHandler(this.trackbarSliderScroll);
  224.         // 
  225.         // labelParamMin1
  226.         // 
  227.         this.labelParamMin1.Location = new System.Drawing.Point(366, 112);
  228.         this.labelParamMin1.Name = "labelParamMin1";
  229.         this.labelParamMin1.Size = new System.Drawing.Size(60, 16);
  230.         this.labelParamMin1.TabIndex = 5;
  231.         this.labelParamMin1.Text = "min";
  232.         this.labelParamMin1.TextAlign = System.Drawing.ContentAlignment.TopCenter;
  233.         // 
  234.         // labelParamMax1
  235.         // 
  236.         this.labelParamMax1.Location = new System.Drawing.Point(627, 120);
  237.         this.labelParamMax1.Name = "labelParamMax1";
  238.         this.labelParamMax1.Size = new System.Drawing.Size(52, 13);
  239.         this.labelParamMax1.TabIndex = 6;
  240.         this.labelParamMax1.Text = "max";
  241.         this.labelParamMax1.TextAlign = System.Drawing.ContentAlignment.TopCenter;
  242.         // 
  243.         // labelParamName2
  244.         // 
  245.         this.labelParamName2.Location = new System.Drawing.Point(169, 160);
  246.         this.labelParamName2.Name = "labelParamName2";
  247.         this.labelParamName2.Size = new System.Drawing.Size(117, 13);
  248.         this.labelParamName2.TabIndex = 7;
  249.         this.labelParamName2.TextAlign = System.Drawing.ContentAlignment.TopRight;
  250.         // 
  251.         // labelParamValue2
  252.         // 
  253.         this.labelParamValue2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
  254.         this.labelParamValue2.Location = new System.Drawing.Point(294, 160);
  255.         this.labelParamValue2.Name = "labelParamValue2";
  256.         this.labelParamValue2.Size = new System.Drawing.Size(67, 16);
  257.         this.labelParamValue2.TabIndex = 8;
  258.         this.labelParamValue2.Text = "Value";
  259.         this.labelParamValue2.TextAlign = System.Drawing.ContentAlignment.TopCenter;
  260.         // 
  261.         // trackbarSlider2
  262.         // 
  263.         this.trackbarSlider2.Location = new System.Drawing.Point(426, 163);
  264.         this.trackbarSlider2.Name = "trackbarSlider2";
  265.         this.trackbarSlider2.Size = new System.Drawing.Size(195, 45);
  266.         this.trackbarSlider2.TabIndex = 9;
  267.         this.trackbarSlider2.Text = "Slider1";
  268.         this.trackbarSlider2.TickStyle = System.Windows.Forms.TickStyle.None;
  269.         this.trackbarSlider2.Scroll += new System.EventHandler(this.trackbarSliderScroll);
  270.         // 
  271.         // labelParamMin2
  272.         // 
  273.         this.labelParamMin2.Location = new System.Drawing.Point(366, 160);
  274.         this.labelParamMin2.Name = "labelParamMin2";
  275.         this.labelParamMin2.Size = new System.Drawing.Size(60, 16);
  276.         this.labelParamMin2.TabIndex = 10;
  277.         this.labelParamMin2.Text = "min";
  278.         this.labelParamMin2.TextAlign = System.Drawing.ContentAlignment.TopCenter;
  279.         // 
  280.         // labelParamMax2
  281.         // 
  282.         this.labelParamMax2.Location = new System.Drawing.Point(627, 168);
  283.         this.labelParamMax2.Name = "labelParamMax2";
  284.         this.labelParamMax2.Size = new System.Drawing.Size(52, 13);
  285.         this.labelParamMax2.TabIndex = 11;
  286.         this.labelParamMax2.Text = "max";
  287.         this.labelParamMax2.TextAlign = System.Drawing.ContentAlignment.TopCenter;
  288.         // 
  289.         // labelParamName3
  290.         // 
  291.         this.labelParamName3.Location = new System.Drawing.Point(169, 208);
  292.         this.labelParamName3.Name = "labelParamName3";
  293.         this.labelParamName3.Size = new System.Drawing.Size(117, 13);
  294.         this.labelParamName3.TabIndex = 12;
  295.         this.labelParamName3.TextAlign = System.Drawing.ContentAlignment.TopRight;
  296.         // 
  297.         // labelParamValue3
  298.         // 
  299.         this.labelParamValue3.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
  300.         this.labelParamValue3.Location = new System.Drawing.Point(294, 208);
  301.         this.labelParamValue3.Name = "labelParamValue3";
  302.         this.labelParamValue3.Size = new System.Drawing.Size(67, 16);
  303.         this.labelParamValue3.TabIndex = 13;
  304.         this.labelParamValue3.Text = "Value";
  305.         this.labelParamValue3.TextAlign = System.Drawing.ContentAlignment.TopCenter;
  306.         // 
  307.         // trackbarSlider3
  308.         // 
  309.         this.trackbarSlider3.Location = new System.Drawing.Point(426, 208);
  310.         this.trackbarSlider3.Name = "trackbarSlider3";
  311.         this.trackbarSlider3.Size = new System.Drawing.Size(195, 45);
  312.         this.trackbarSlider3.TabIndex = 14;
  313.         this.trackbarSlider3.Text = "Slider1";
  314.         this.trackbarSlider3.TickStyle = System.Windows.Forms.TickStyle.None;
  315.         this.trackbarSlider3.Scroll += new System.EventHandler(this.trackbarSliderScroll);
  316.         // 
  317.         // labelParamMin3
  318.         // 
  319.         this.labelParamMin3.Location = new System.Drawing.Point(366, 208);
  320.         this.labelParamMin3.Name = "labelParamMin3";
  321.         this.labelParamMin3.Size = new System.Drawing.Size(60, 16);
  322.         this.labelParamMin3.TabIndex = 15;
  323.         this.labelParamMin3.Text = "min";
  324.         this.labelParamMin3.TextAlign = System.Drawing.ContentAlignment.TopCenter;
  325.         // 
  326.         // labelParamMax3
  327.         // 
  328.         this.labelParamMax3.Location = new System.Drawing.Point(627, 216);
  329.         this.labelParamMax3.Name = "labelParamMax3";
  330.         this.labelParamMax3.Size = new System.Drawing.Size(52, 13);
  331.         this.labelParamMax3.TabIndex = 16;
  332.         this.labelParamMax3.Text = "max";
  333.         this.labelParamMax3.TextAlign = System.Drawing.ContentAlignment.TopCenter;
  334.         // 
  335.         // labelParamName4
  336.         // 
  337.         this.labelParamName4.Location = new System.Drawing.Point(169, 256);
  338.         this.labelParamName4.Name = "labelParamName4";
  339.         this.labelParamName4.Size = new System.Drawing.Size(117, 13);
  340.         this.labelParamName4.TabIndex = 17;
  341.         this.labelParamName4.TextAlign = System.Drawing.ContentAlignment.TopRight;
  342.         // 
  343.         // labelParamValue4
  344.         // 
  345.         this.labelParamValue4.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
  346.         this.labelParamValue4.Location = new System.Drawing.Point(294, 256);
  347.         this.labelParamValue4.Name = "labelParamValue4";
  348.         this.labelParamValue4.Size = new System.Drawing.Size(67, 16);
  349.         this.labelParamValue4.TabIndex = 18;
  350.         this.labelParamValue4.Text = "Value";
  351.         this.labelParamValue4.TextAlign = System.Drawing.ContentAlignment.TopCenter;
  352.         // 
  353.         // trackbarSlider4
  354.         // 
  355.         this.trackbarSlider4.Location = new System.Drawing.Point(426, 256);
  356.         this.trackbarSlider4.Name = "trackbarSlider4";
  357.         this.trackbarSlider4.Size = new System.Drawing.Size(195, 45);
  358.         this.trackbarSlider4.TabIndex = 19;
  359.         this.trackbarSlider4.Text = "Slider1";
  360.         this.trackbarSlider4.TickStyle = System.Windows.Forms.TickStyle.None;
  361.         this.trackbarSlider4.Scroll += new System.EventHandler(this.trackbarSliderScroll);
  362.         // 
  363.         // labelParamMin4
  364.         // 
  365.         this.labelParamMin4.Location = new System.Drawing.Point(366, 256);
  366.         this.labelParamMin4.Name = "labelParamMin4";
  367.         this.labelParamMin4.Size = new System.Drawing.Size(60, 16);
  368.         this.labelParamMin4.TabIndex = 20;
  369.         this.labelParamMin4.Text = "min";
  370.         this.labelParamMin4.TextAlign = System.Drawing.ContentAlignment.TopCenter;
  371.         // 
  372.         // labelParamMax4
  373.         // 
  374.         this.labelParamMax4.Location = new System.Drawing.Point(627, 256);
  375.         this.labelParamMax4.Name = "labelParamMax4";
  376.         this.labelParamMax4.Size = new System.Drawing.Size(52, 13);
  377.         this.labelParamMax4.TabIndex = 21;
  378.         this.labelParamMax4.Text = "max";
  379.         this.labelParamMax4.TextAlign = System.Drawing.ContentAlignment.TopCenter;
  380.         // 
  381.         // labelParamName5
  382.         // 
  383.         this.labelParamName5.Location = new System.Drawing.Point(169, 304);
  384.         this.labelParamName5.Name = "labelParamName5";
  385.         this.labelParamName5.Size = new System.Drawing.Size(117, 13);
  386.         this.labelParamName5.TabIndex = 22;
  387.         this.labelParamName5.TextAlign = System.Drawing.ContentAlignment.TopRight;
  388.         // 
  389.         // labelParamValue5
  390.         // 
  391.         this.labelParamValue5.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
  392.         this.labelParamValue5.Location = new System.Drawing.Point(294, 304);
  393.         this.labelParamValue5.Name = "labelParamValue5";
  394.         this.labelParamValue5.Size = new System.Drawing.Size(67, 16);
  395.         this.labelParamValue5.TabIndex = 23;
  396.         this.labelParamValue5.Text = "Value";
  397.         this.labelParamValue5.TextAlign = System.Drawing.ContentAlignment.TopCenter;
  398.         // 
  399.         // trackbarSlider5
  400.         // 
  401.         this.trackbarSlider5.Location = new System.Drawing.Point(426, 304);
  402.         this.trackbarSlider5.Name = "trackbarSlider5";
  403.         this.trackbarSlider5.Size = new System.Drawing.Size(195, 45);
  404.         this.trackbarSlider5.TabIndex = 24;
  405.         this.trackbarSlider5.Text = "Slider1";
  406.         this.trackbarSlider5.TickStyle = System.Windows.Forms.TickStyle.None;
  407.         this.trackbarSlider5.Scroll += new System.EventHandler(this.trackbarSliderScroll);
  408.         // 
  409.         // labelParamMin5
  410.         // 
  411.         this.labelParamMin5.Location = new System.Drawing.Point(366, 304);
  412.         this.labelParamMin5.Name = "labelParamMin5";
  413.         this.labelParamMin5.Size = new System.Drawing.Size(60, 16);
  414.         this.labelParamMin5.TabIndex = 25;
  415.         this.labelParamMin5.Text = "min";
  416.         this.labelParamMin5.TextAlign = System.Drawing.ContentAlignment.TopCenter;
  417.         // 
  418.         // labelParamMax5
  419.         // 
  420.         this.labelParamMax5.Location = new System.Drawing.Point(627, 312);
  421.         this.labelParamMax5.Name = "labelParamMax5";
  422.         this.labelParamMax5.Size = new System.Drawing.Size(52, 13);
  423.         this.labelParamMax5.TabIndex = 26;
  424.         this.labelParamMax5.Text = "max";
  425.         this.labelParamMax5.TextAlign = System.Drawing.ContentAlignment.TopCenter;
  426.         // 
  427.         // labelParamName6
  428.         // 
  429.         this.labelParamName6.Location = new System.Drawing.Point(169, 352);
  430.         this.labelParamName6.Name = "labelParamName6";
  431.         this.labelParamName6.Size = new System.Drawing.Size(117, 13);
  432.         this.labelParamName6.TabIndex = 27;
  433.         this.labelParamName6.TextAlign = System.Drawing.ContentAlignment.TopRight;
  434.         // 
  435.         // labelParamValue6
  436.         // 
  437.         this.labelParamValue6.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
  438.         this.labelParamValue6.Location = new System.Drawing.Point(294, 352);
  439.         this.labelParamValue6.Name = "labelParamValue6";
  440.         this.labelParamValue6.Size = new System.Drawing.Size(67, 16);
  441.         this.labelParamValue6.TabIndex = 28;
  442.         this.labelParamValue6.Text = "Value";
  443.         this.labelParamValue6.TextAlign = System.Drawing.ContentAlignment.TopCenter;
  444.         // 
  445.         // trackbarSlider6
  446.         // 
  447.         this.trackbarSlider6.Location = new System.Drawing.Point(426, 352);
  448.         this.trackbarSlider6.Name = "trackbarSlider6";
  449.         this.trackbarSlider6.Size = new System.Drawing.Size(195, 45);
  450.         this.trackbarSlider6.TabIndex = 29;
  451.         this.trackbarSlider6.Text = "Slider1";
  452.         this.trackbarSlider6.TickStyle = System.Windows.Forms.TickStyle.None;
  453.         this.trackbarSlider6.Scroll += new System.EventHandler(this.trackbarSliderScroll);
  454.         // 
  455.         // labelParamMin6
  456.         // 
  457.         this.labelParamMin6.Location = new System.Drawing.Point(366, 352);
  458.         this.labelParamMin6.Name = "labelParamMin6";
  459.         this.labelParamMin6.Size = new System.Drawing.Size(60, 16);
  460.         this.labelParamMin6.TabIndex = 30;
  461.         this.labelParamMin6.Text = "min";
  462.         this.labelParamMin6.TextAlign = System.Drawing.ContentAlignment.TopCenter;
  463.         // 
  464.         // labelParamMax6
  465.         // 
  466.         this.labelParamMax6.Location = new System.Drawing.Point(627, 352);
  467.         this.labelParamMax6.Name = "labelParamMax6";
  468.         this.labelParamMax6.Size = new System.Drawing.Size(52, 13);
  469.         this.labelParamMax6.TabIndex = 31;
  470.         this.labelParamMax6.Text = "max";
  471.         this.labelParamMax6.TextAlign = System.Drawing.ContentAlignment.TopCenter;
  472.         // 
  473.         // radiobuttonTriangle
  474.         // 
  475.         this.radiobuttonTriangle.Location = new System.Drawing.Point(16, 16);
  476.         this.radiobuttonTriangle.Name = "radiobuttonTriangle";
  477.         this.radiobuttonTriangle.Size = new System.Drawing.Size(69, 16);
  478.         this.radiobuttonTriangle.TabIndex = 32;
  479.         this.radiobuttonTriangle.Text = "Triangle";
  480.         this.radiobuttonTriangle.CheckedChanged += new System.EventHandler(this.trackbarSliderScroll);
  481.         // 
  482.         // radiobuttonSquare
  483.         // 
  484.         this.radiobuttonSquare.Location = new System.Drawing.Point(88, 16);
  485.         this.radiobuttonSquare.Name = "radiobuttonSquare";
  486.         this.radiobuttonSquare.Size = new System.Drawing.Size(64, 16);
  487.         this.radiobuttonSquare.TabIndex = 33;
  488.         this.radiobuttonSquare.Text = "Square";
  489.         this.radiobuttonSquare.CheckedChanged += new System.EventHandler(this.trackbarSliderScroll);
  490.         // 
  491.         // radiobuttonRadioSine
  492.         // 
  493.         this.radiobuttonRadioSine.Location = new System.Drawing.Point(152, 16);
  494.         this.radiobuttonRadioSine.Name = "radiobuttonRadioSine";
  495.         this.radiobuttonRadioSine.Size = new System.Drawing.Size(48, 16);
  496.         this.radiobuttonRadioSine.TabIndex = 34;
  497.         this.radiobuttonRadioSine.Text = "Sine";
  498.         this.radiobuttonRadioSine.CheckedChanged += new System.EventHandler(this.trackbarSliderScroll);
  499.         // 
  500.         // groupboxFrameWaveform
  501.         // 
  502.         this.groupboxFrameWaveform.Controls.AddRange(new System.Windows.Forms.Control[] {
  503.                                                                                             this.radiobuttonSquare,
  504.                                                                                             this.radiobuttonTriangle,
  505.                                                                                             this.radiobuttonRadioSine});
  506.         this.groupboxFrameWaveform.Location = new System.Drawing.Point(180, 400);
  507.         this.groupboxFrameWaveform.Name = "groupboxFrameWaveform";
  508.         this.groupboxFrameWaveform.Size = new System.Drawing.Size(225, 42);
  509.         this.groupboxFrameWaveform.TabIndex = 35;
  510.         this.groupboxFrameWaveform.TabStop = false;
  511.         this.groupboxFrameWaveform.Text = "Waveform";
  512.         // 
  513.         // buttonOpen
  514.         // 
  515.         this.buttonOpen.Location = new System.Drawing.Point(12, 12);
  516.         this.buttonOpen.Name = "buttonOpen";
  517.         this.buttonOpen.TabIndex = 47;
  518.         this.buttonOpen.Text = "&Open File";
  519.         this.buttonOpen.Click += new System.EventHandler(this.buttonOpen_Click);
  520.         // 
  521.         // labelTextFilename
  522.         // 
  523.         this.labelTextFilename.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
  524.         this.labelTextFilename.Location = new System.Drawing.Point(94, 14);
  525.         this.labelTextFilename.Name = "labelTextFilename";
  526.         this.labelTextFilename.Size = new System.Drawing.Size(595, 20);
  527.         this.labelTextFilename.TabIndex = 48;
  528.         this.labelTextFilename.Text = "Filename";
  529.         this.labelTextFilename.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  530.         // 
  531.         // labelStatic2
  532.         // 
  533.         this.labelStatic2.Location = new System.Drawing.Point(19, 44);
  534.         this.labelStatic2.Name = "labelStatic2";
  535.         this.labelStatic2.Size = new System.Drawing.Size(67, 16);
  536.         this.labelStatic2.TabIndex = 49;
  537.         this.labelStatic2.Text = "Status";
  538.         // 
  539.         // labelTextStatus
  540.         // 
  541.         this.labelTextStatus.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
  542.         this.labelTextStatus.Location = new System.Drawing.Point(94, 44);
  543.         this.labelTextStatus.Name = "labelTextStatus";
  544.         this.labelTextStatus.Size = new System.Drawing.Size(595, 20);
  545.         this.labelTextStatus.TabIndex = 50;
  546.         this.labelTextStatus.Text = "No file loaded.";
  547.         this.labelTextStatus.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  548.         // 
  549.         // checkboxLoop
  550.         // 
  551.         this.checkboxLoop.Location = new System.Drawing.Point(42, 376);
  552.         this.checkboxLoop.Name = "checkboxLoop";
  553.         this.checkboxLoop.Size = new System.Drawing.Size(86, 16);
  554.         this.checkboxLoop.TabIndex = 51;
  555.         this.checkboxLoop.Text = "&Loop Sound";
  556.         this.checkboxLoop.CheckedChanged += new System.EventHandler(this.checkboxLoop_CheckedChanged);
  557.         // 
  558.         // buttonPlay
  559.         // 
  560.         this.buttonPlay.Location = new System.Drawing.Point(10, 400);
  561.         this.buttonPlay.Name = "buttonPlay";
  562.         this.buttonPlay.Size = new System.Drawing.Size(67, 23);
  563.         this.buttonPlay.TabIndex = 52;
  564.         this.buttonPlay.Text = "&Play";
  565.         this.buttonPlay.Click += new System.EventHandler(this.buttonPlay_Click);
  566.         // 
  567.         // buttonStop
  568.         // 
  569.         this.buttonStop.Location = new System.Drawing.Point(87, 400);
  570.         this.buttonStop.Name = "buttonStop";
  571.         this.buttonStop.Size = new System.Drawing.Size(67, 23);
  572.         this.buttonStop.TabIndex = 53;
  573.         this.buttonStop.Text = "&Stop";
  574.         this.buttonStop.Enabled = false;
  575.         this.buttonStop.Click += new System.EventHandler(this.buttonStop_Click);
  576.         // 
  577.         // labelStatic3
  578.         // 
  579.         this.labelStatic3.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
  580.         this.labelStatic3.Location = new System.Drawing.Point(372, 88);
  581.         this.labelStatic3.Name = "labelStatic3";
  582.         this.labelStatic3.Size = new System.Drawing.Size(52, 16);
  583.         this.labelStatic3.TabIndex = 62;
  584.         this.labelStatic3.Text = "Min";
  585.         this.labelStatic3.TextAlign = System.Drawing.ContentAlignment.TopCenter;
  586.         // 
  587.         // labelStatic4
  588.         // 
  589.         this.labelStatic4.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
  590.         this.labelStatic4.Location = new System.Drawing.Point(627, 88);
  591.         this.labelStatic4.Name = "labelStatic4";
  592.         this.labelStatic4.Size = new System.Drawing.Size(52, 16);
  593.         this.labelStatic4.TabIndex = 64;
  594.         this.labelStatic4.Text = "Max";
  595.         this.labelStatic4.TextAlign = System.Drawing.ContentAlignment.TopCenter;
  596.         // 
  597.         // radiobuttonRadioNeg180
  598.         // 
  599.         this.radiobuttonRadioNeg180.Location = new System.Drawing.Point(16, 16);
  600.         this.radiobuttonRadioNeg180.Name = "radiobuttonRadioNeg180";
  601.         this.radiobuttonRadioNeg180.Size = new System.Drawing.Size(45, 16);
  602.         this.radiobuttonRadioNeg180.TabIndex = 65;
  603.         this.radiobuttonRadioNeg180.Text = "-180";
  604.         this.radiobuttonRadioNeg180.CheckedChanged += new System.EventHandler(this.trackbarSliderScroll);
  605.         // 
  606.         // radiobuttonRadioNeg90
  607.         // 
  608.         this.radiobuttonRadioNeg90.Location = new System.Drawing.Point(72, 16);
  609.         this.radiobuttonRadioNeg90.Name = "radiobuttonRadioNeg90";
  610.         this.radiobuttonRadioNeg90.Size = new System.Drawing.Size(39, 16);
  611.         this.radiobuttonRadioNeg90.TabIndex = 66;
  612.         this.radiobuttonRadioNeg90.Text = "-90";
  613.         this.radiobuttonRadioNeg90.CheckedChanged += new System.EventHandler(this.trackbarSliderScroll);
  614.         // 
  615.         // radiobuttonRadioZero
  616.         // 
  617.         this.radiobuttonRadioZero.Location = new System.Drawing.Point(120, 16);
  618.         this.radiobuttonRadioZero.Name = "radiobuttonRadioZero";
  619.         this.radiobuttonRadioZero.Size = new System.Drawing.Size(30, 16);
  620.         this.radiobuttonRadioZero.TabIndex = 67;
  621.         this.radiobuttonRadioZero.Text = "0";
  622.         this.radiobuttonRadioZero.CheckedChanged += new System.EventHandler(this.trackbarSliderScroll);
  623.         // 
  624.         // radiobuttonRadio90
  625.         // 
  626.         this.radiobuttonRadio90.Location = new System.Drawing.Point(152, 16);
  627.         this.radiobuttonRadio90.Name = "radiobuttonRadio90";
  628.         this.radiobuttonRadio90.Size = new System.Drawing.Size(36, 16);
  629.         this.radiobuttonRadio90.TabIndex = 68;
  630.         this.radiobuttonRadio90.Text = "90";
  631.         this.radiobuttonRadio90.CheckedChanged += new System.EventHandler(this.trackbarSliderScroll);
  632.         // 
  633.         // radiobuttonRadio180
  634.         // 
  635.         this.radiobuttonRadio180.Location = new System.Drawing.Point(200, 16);
  636.         this.radiobuttonRadio180.Name = "radiobuttonRadio180";
  637.         this.radiobuttonRadio180.Size = new System.Drawing.Size(42, 16);
  638.         this.radiobuttonRadio180.TabIndex = 69;
  639.         this.radiobuttonRadio180.Text = "180";
  640.         this.radiobuttonRadio180.CheckedChanged += new System.EventHandler(this.trackbarSliderScroll);
  641.         // 
  642.         // groupboxFramePhase
  643.         // 
  644.         this.groupboxFramePhase.Controls.AddRange(new System.Windows.Forms.Control[] {
  645.                                                                                          this.radiobuttonRadioNeg180,
  646.                                                                                          this.radiobuttonRadioNeg90,
  647.                                                                                          this.radiobuttonRadioZero,
  648.                                                                                          this.radiobuttonRadio90,
  649.                                                                                          this.radiobuttonRadio180});
  650.         this.groupboxFramePhase.Location = new System.Drawing.Point(420, 400);
  651.         this.groupboxFramePhase.Name = "groupboxFramePhase";
  652.         this.groupboxFramePhase.Size = new System.Drawing.Size(247, 42);
  653.         this.groupboxFramePhase.TabIndex = 63;
  654.         this.groupboxFramePhase.TabStop = false;
  655.         this.groupboxFramePhase.Text = "Phase (Degrees)";
  656.         // 
  657.         // groupboxEffects
  658.         // 
  659.         this.groupboxEffects.Controls.AddRange(new System.Windows.Forms.Control[] {
  660.                                                                                       this.buttonDelete,
  661.                                                                                       this.listboxEffects,
  662.                                                                                       this.comboEffects});
  663.         this.groupboxEffects.Location = new System.Drawing.Point(8, 80);
  664.         this.groupboxEffects.Name = "groupboxEffects";
  665.         this.groupboxEffects.Size = new System.Drawing.Size(144, 280);
  666.         this.groupboxEffects.TabIndex = 71;
  667.         this.groupboxEffects.TabStop = false;
  668.         this.groupboxEffects.Text = "Effects";
  669.         // 
  670.         // buttonDelete
  671.         // 
  672.         this.buttonDelete.Location = new System.Drawing.Point(40, 248);
  673.         this.buttonDelete.Name = "buttonDelete";
  674.         this.buttonDelete.Size = new System.Drawing.Size(64, 24);
  675.         this.buttonDelete.TabIndex = 3;
  676.         this.buttonDelete.Text = "Delete";
  677.         this.buttonDelete.Click += new System.EventHandler(this.buttonDelete_Click);
  678.         // 
  679.         // listboxEffects
  680.         // 
  681.         this.listboxEffects.Location = new System.Drawing.Point(8, 48);
  682.         this.listboxEffects.Name = "listboxEffects";
  683.         this.listboxEffects.Size = new System.Drawing.Size(128, 186);
  684.         this.listboxEffects.TabIndex = 2;
  685.         this.listboxEffects.KeyUp += new System.Windows.Forms.KeyEventHandler(this.listboxEffects_KeyUp);
  686.         this.listboxEffects.SelectedIndexChanged += new System.EventHandler(this.listboxEffects_SelectedIndexChanged);
  687.         // 
  688.         // comboEffects
  689.         // 
  690.         this.comboEffects.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  691.         this.comboEffects.Items.AddRange(new object[] {
  692.                                                           "Chorus",
  693.                                                           "Compressor",
  694.                                                           "Distortion",
  695.                                                           "Echo",
  696.                                                           "Flanger",
  697.                                                           "Gargle",
  698.                                                           "Waves Reverb",
  699.                                                           "ParamEq"});
  700.         this.comboEffects.Location = new System.Drawing.Point(8, 16);
  701.         this.comboEffects.Name = "comboEffects";
  702.         this.comboEffects.Size = new System.Drawing.Size(128, 21);
  703.         this.comboEffects.TabIndex = 1;
  704.         this.comboEffects.SelectedValueChanged += new System.EventHandler(this.comboEffects_SelectedValueChanged);
  705.         // 
  706.         // timer1
  707.         // 
  708.         this.timer1.Interval = 50;
  709.         this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
  710.         // 
  711.         // MainForm
  712.         // 
  713.         this.AcceptButton = this.buttonOk;
  714.         this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  715.         this.ClientSize = new System.Drawing.Size(700, 472);
  716.         this.Controls.AddRange(new System.Windows.Forms.Control[] {
  717.                                                                       this.groupboxEffects,
  718.                                                                       this.buttonOk,
  719.                                                                       this.labelParamName1,
  720.                                                                       this.labelParamValue1,
  721.                                                                       this.trackbarSlider1,
  722.                                                                       this.labelParamMin1,
  723.                                                                       this.labelParamMax1,
  724.                                                                       this.labelParamName2,
  725.                                                                       this.labelParamValue2,
  726.                                                                       this.trackbarSlider2,
  727.                                                                       this.labelParamMin2,
  728.                                                                       this.labelParamMax2,
  729.                                                                       this.labelParamName3,
  730.                                                                       this.labelParamValue3,
  731.                                                                       this.trackbarSlider3,
  732.                                                                       this.labelParamMin3,
  733.                                                                       this.labelParamMax3,
  734.                                                                       this.labelParamName4,
  735.                                                                       this.labelParamValue4,
  736.                                                                       this.trackbarSlider4,
  737.                                                                       this.labelParamMin4,
  738.                                                                       this.labelParamMax4,
  739.                                                                       this.labelParamName5,
  740.                                                                       this.labelParamValue5,
  741.                                                                       this.trackbarSlider5,
  742.                                                                       this.labelParamMin5,
  743.                                                                       this.labelParamMax5,
  744.                                                                       this.labelParamName6,
  745.                                                                       this.labelParamValue6,
  746.                                                                       this.trackbarSlider6,
  747.                                                                       this.labelParamMin6,
  748.                                                                       this.labelParamMax6,
  749.                                                                       this.buttonOpen,
  750.                                                                       this.labelTextFilename,
  751.                                                                       this.labelStatic2,
  752.                                                                       this.labelTextStatus,
  753.                                                                       this.checkboxLoop,
  754.                                                                       this.buttonPlay,
  755.                                                                       this.buttonStop,
  756.                                                                       this.labelStatic3,
  757.                                                                       this.labelStatic4,
  758.                                                                       this.groupboxFrameWaveform,
  759.                                                                       this.groupboxFramePhase,
  760.                                                                       this.groupboxFrame});
  761.         this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
  762.         this.Location = new System.Drawing.Point(150, 160);
  763.         this.MaximizeBox = false;
  764.         this.Name = "MainForm";
  765.         this.Text = "SoundFX - Sound effects applied to Device.SecondaryBuffer";
  766.         this.Closing += new System.ComponentModel.CancelEventHandler(this.MainForm_Closing);
  767.         ((System.ComponentModel.ISupportInitialize)(this.trackbarSlider1)).EndInit();
  768.         ((System.ComponentModel.ISupportInitialize)(this.trackbarSlider2)).EndInit();
  769.         ((System.ComponentModel.ISupportInitialize)(this.trackbarSlider3)).EndInit();
  770.         ((System.ComponentModel.ISupportInitialize)(this.trackbarSlider4)).EndInit();
  771.         ((System.ComponentModel.ISupportInitialize)(this.trackbarSlider5)).EndInit();
  772.         ((System.ComponentModel.ISupportInitialize)(this.trackbarSlider6)).EndInit();
  773.         this.groupboxFrameWaveform.ResumeLayout(false);
  774.         this.groupboxFramePhase.ResumeLayout(false);
  775.         this.groupboxEffects.ResumeLayout(false);
  776.         this.ResumeLayout(false);
  777.  
  778.     }
  779.     #endregion
  780.     private void InitDirectSound()
  781.     {
  782.         BufferDescription description = new BufferDescription();
  783.         WaveFormat wfx = new WaveFormat();
  784.  
  785.         try
  786.         {
  787.             applicationDevice = new Device();
  788.             applicationDevice.SetCooperativeLevel(this, CooperativeLevel.Priority);
  789.         }
  790.         catch
  791.         {
  792.             MessageBox.Show("Unable to create sound device. Sample will now exit.");
  793.             this.Close();
  794.             throw;
  795.         }
  796.     }
  797.     protected override void Dispose(bool disposing)
  798.     {
  799.         if (disposing)
  800.         {
  801.             if (applicationBuffer != null)
  802.                 applicationBuffer.Dispose();
  803.             if (applicationDevice != null)
  804.                 applicationDevice.Dispose();
  805.         }
  806.         base.Dispose (disposing);
  807.     }
  808.  
  809.     private void buttonOpen_Click(object sender, System.EventArgs e)
  810.     {
  811.         BufferDescription description = new BufferDescription();
  812.         OpenFileDialog ofd = new OpenFileDialog();
  813.  
  814.         labelTextStatus.Text = "Loading file...";
  815.         // Get the default media path (something like C:\WINDOWS\MEDIA)
  816.         if (string.Empty == path)
  817.             path = Environment.SystemDirectory.Substring(0, Environment.SystemDirectory.LastIndexOf("\\")) + "\\media";
  818.  
  819.         ofd.DefaultExt = ".wav";
  820.         ofd.Filter = "Wave Files|*.wav|All Files|*.*";
  821.         ofd.FileName = fileName;
  822.         ofd.InitialDirectory = path;
  823.  
  824.         if (null != applicationBuffer)
  825.         {
  826.             applicationBuffer.Stop();
  827.             applicationBuffer.SetCurrentPosition(0);
  828.         }
  829.  
  830.         // Display the OpenFileName dialog. Then, try to load the specified file
  831.         if (DialogResult.Cancel == ofd.ShowDialog(this))
  832.         {
  833.             if(null != applicationBuffer)
  834.                 applicationBuffer.Dispose();
  835.  
  836.             labelTextStatus.Text = "No file loaded.";
  837.             return;
  838.         }
  839.         fileName = string.Empty;
  840.  
  841.         description.ControlEffects = true;
  842.     
  843.         // Create a SecondaryBuffer using the file name.
  844.         try
  845.         {
  846.             applicationBuffer = new SecondaryBuffer(ofd.FileName, description,  applicationDevice);
  847.         }
  848.         catch(BufferTooSmallException)
  849.         {
  850.             labelTextStatus.Text = "Wave file is too small to be used with effects.";
  851.             return;
  852.         }
  853.         catch(FormatException)
  854.         {
  855.             // Invalid file was used. Managed DirectSound tries to convert any files less than
  856.             // 8 bit to 8 bit. Some drivers don't support this conversion, so make sure to
  857.             // catch the FormatException if it's thrown.
  858.             labelTextStatus.Text = "Failed to create SecondaryBuffer from selected file.";
  859.             return;
  860.         }
  861.         
  862.         // Remember the file for next time
  863.         if (null != applicationBuffer)
  864.         {
  865.             fileName = ofd.FileName;
  866.             path =  fileName.Substring(0, fileName.LastIndexOf("\\"));
  867.         }
  868.         labelTextFilename.Text = fileName;
  869.         labelTextStatus.Text = "File loaded.";
  870.     }
  871.     private void buttonPlay_Click(object sender, System.EventArgs e)
  872.     {
  873.         BufferPlayFlags bpf = new BufferPlayFlags();
  874.  
  875.         if (null != applicationBuffer)
  876.         {
  877.             applicationBuffer.Play(0, (shouldLoop == true) ? BufferPlayFlags.Looping : BufferPlayFlags.Default);
  878.             timer1.Enabled = true;
  879.             buttonStop.Enabled = true;
  880.             buttonPlay.Enabled = false;
  881.             comboEffects.Enabled = false;
  882.             labelTextStatus.Text="Sound playing.";
  883.         }
  884.     }
  885.     private void buttonStop_Click(object sender, System.EventArgs e)
  886.     {
  887.         if (null != applicationBuffer)
  888.             if (applicationBuffer.Status.Playing == true)
  889.             {
  890.                 applicationBuffer.Stop();
  891.                 applicationBuffer.SetCurrentPosition(0);
  892.                 timer1.Enabled = false;
  893.                 buttonStop.Enabled = false;
  894.                 buttonPlay.Enabled = true;
  895.                 comboEffects.Enabled = true;
  896.                 labelTextStatus.Text="Sound stopped.";
  897.             }
  898.     }
  899.     private void comboEffects_SelectedValueChanged(object sender, System.EventArgs e)
  900.     {
  901.         string description  = string.Empty;
  902.  
  903.         if (null == applicationBuffer)
  904.             return;
  905.  
  906.         EffectInfo[] temp = new EffectInfo[effectDescription.Count + 1];
  907.         effectDescription.CopyTo(temp, 0);
  908.  
  909.         switch (comboEffects.SelectedIndex)
  910.         {
  911.             case 0:
  912.                 temp[temp.Length - 1].description.GuidEffectClass = DSoundHelper.StandardChorusGuid;
  913.                 description = "Chorus";
  914.                 break;
  915.             case 1:
  916.                 temp[temp.Length - 1].description.GuidEffectClass = DSoundHelper.StandardCompressorGuid;
  917.                 description = "Compressor";
  918.                 break;
  919.             case 2:
  920.                 temp[temp.Length - 1].description.GuidEffectClass = DSoundHelper.StandardDistortionGuid;
  921.                 description = "Distortion";
  922.                 break;
  923.             case 3:
  924.                 temp[temp.Length - 1].description.GuidEffectClass = DSoundHelper.StandardEchoGuid;
  925.                 description = "Echo";
  926.                 break;
  927.             case 4:
  928.                 temp[temp.Length - 1].description.GuidEffectClass = DSoundHelper.StandardFlangerGuid;
  929.                 description = "Flanger";
  930.                 break;
  931.             case 5:
  932.                 temp[temp.Length - 1].description.GuidEffectClass = DSoundHelper.StandardGargleGuid;
  933.                 description = "Gargle";
  934.                 break;
  935.             case 6:
  936.                 temp[temp.Length - 1].description.GuidEffectClass = DSoundHelper.StandardWavesReverbGuid;
  937.                 description = "Waves Reverb";
  938.                 break;
  939.             case 7:
  940.                 temp[temp.Length - 1].description.GuidEffectClass = DSoundHelper.StandardParamEqGuid;
  941.                 description = "ParamEq";
  942.                 break;
  943.         }       
  944.         
  945.         if (AddEffect(temp))
  946.         {
  947.             effectDescription.Clear();
  948.             effectDescription.AddRange(temp);
  949.             listboxEffects.Items.Add(description);
  950.             listboxEffects.SelectedIndex = listboxEffects.Items.Count - 1;
  951.         }
  952.         
  953.     }
  954.     private bool AddEffect(EffectInfo[] temp)
  955.     {
  956.         EffectsReturnValue[] ret = null;
  957.         EffectDescription[] fx = null;      
  958.         bool WasPlaying = false;        
  959.         int count = 0;
  960.  
  961.         if (null != temp)
  962.         {
  963.             fx = new EffectDescription[temp.Length];
  964.             count = temp.Length;
  965.         }
  966.  
  967.         if (true == applicationBuffer.Status.Playing)
  968.             WasPlaying = true;
  969.         
  970.         applicationBuffer.Stop();
  971.         
  972.         // Store the current params for each effect.
  973.         for (int i=0; i < count; i++)
  974.             fx[i] = ((EffectInfo)temp[i]).description;
  975.  
  976.         try
  977.         {
  978.             ret = applicationBuffer.SetEffects(fx);
  979.         }
  980.         catch(DirectXException)
  981.         {
  982.             labelTextStatus.Text = "Unable to set effect on the buffer. Some effects can't be set on 8 bit wave files.";
  983.  
  984.             // Revert to the last valid effects.
  985.             if(temp.Length <= 1)
  986.                 return false;
  987.  
  988.             fx = new EffectDescription[temp.Length -1];;
  989.             for (int i=0; i < count - 1; i++)
  990.                 fx[i] = ((EffectInfo)temp[i]).description;
  991.  
  992.             try{ applicationBuffer.SetEffects(fx); }
  993.             catch(DirectXException){}
  994.  
  995.             return false;
  996.         }
  997.         
  998.         // Restore the params for each effect.
  999.         for (int i=0; i < count; i++)
  1000.         {
  1001.             EffectInfo eff = new EffectInfo();
  1002.  
  1003.             eff.Effect = applicationBuffer.GetEffects(i);
  1004.             eff.EffectSettings = temp[i].EffectSettings;
  1005.             eff.description = temp[i].description;
  1006.  
  1007.             Type efftype = eff.Effect.GetType();
  1008.  
  1009.             if (typeof(ChorusEffect) == efftype)
  1010.                 if (null != eff.EffectSettings)
  1011.                     ((ChorusEffect)eff.Effect).AllParameters = (EffectsChorus)eff.EffectSettings;
  1012.                 else
  1013.                     eff.EffectSettings = ((ChorusEffect)eff.Effect).AllParameters;
  1014.             else if (typeof(CompressorEffect) ==efftype)
  1015.                 if (null != eff.EffectSettings)
  1016.                     ((CompressorEffect)eff.Effect).AllParameters = (EffectsCompressor)eff.EffectSettings;
  1017.                 else
  1018.                     eff.EffectSettings = ((CompressorEffect)eff.Effect).AllParameters;
  1019.             else if (typeof(DistortionEffect) == efftype)
  1020.                 if (null != eff.EffectSettings)
  1021.                     ((DistortionEffect)eff.Effect).AllParameters = (EffectsDistortion)eff.EffectSettings;
  1022.                 else
  1023.                     eff.EffectSettings = ((DistortionEffect)eff.Effect).AllParameters;
  1024.             else if (typeof(EchoEffect) == efftype)
  1025.                 if (null != eff.EffectSettings)
  1026.                     ((EchoEffect)eff.Effect).AllParameters = (EffectsEcho)eff.EffectSettings;
  1027.                 else
  1028.                     eff.EffectSettings = ((EchoEffect)eff.Effect).AllParameters;
  1029.             else if (typeof(FlangerEffect) == efftype)
  1030.                      if (null != eff.EffectSettings)
  1031.                          ((FlangerEffect)eff.Effect).AllParameters = (EffectsFlanger)eff.EffectSettings;
  1032.                      else
  1033.                          eff.EffectSettings = ((FlangerEffect)eff.Effect).AllParameters;
  1034.             else if (typeof(GargleEffect) == efftype)
  1035.                      if (null != eff.EffectSettings)
  1036.                          ((GargleEffect)eff.Effect).AllParameters = (EffectsGargle)eff.EffectSettings;
  1037.                      else
  1038.                          eff.EffectSettings = ((GargleEffect)eff.Effect).AllParameters;
  1039.             else if (typeof(ParamEqEffect) == efftype)
  1040.                      if (null != eff.EffectSettings)
  1041.                          ((ParamEqEffect)eff.Effect).AllParameters = (EffectsParamEq)eff.EffectSettings;
  1042.                      else
  1043.                          eff.EffectSettings = ((ParamEqEffect)eff.Effect).AllParameters;
  1044.             else if (typeof(WavesReverbEffect) == efftype)
  1045.                      if (null != eff.EffectSettings)
  1046.                          ((WavesReverbEffect)eff.Effect).AllParameters = (EffectsWavesReverb)eff.EffectSettings;
  1047.                      else
  1048.                          eff.EffectSettings = ((WavesReverbEffect)eff.Effect).AllParameters;
  1049.  
  1050.             temp[i] = eff;
  1051.         }
  1052.         
  1053.         if (WasPlaying)
  1054.             applicationBuffer.Play(0, (shouldLoop == true) ? BufferPlayFlags.Looping : BufferPlayFlags.Default);
  1055.  
  1056.         if (null != temp)
  1057.             if ((EffectsReturnValue.LocatedInHardware == ret[temp.Length - 1]) || (EffectsReturnValue.LocatedInSoftware == ret[temp.Length - 1]))
  1058.                 return true;
  1059.  
  1060.         return false;
  1061.     }
  1062.     private void checkboxLoop_CheckedChanged(object sender, System.EventArgs e)
  1063.     {
  1064.         shouldLoop = checkboxLoop.Checked;
  1065.     }
  1066.     private void listboxEffects_SelectedIndexChanged(object sender, System.EventArgs e)
  1067.     {
  1068.         if (-1 == listboxEffects.SelectedIndex)
  1069.             return;
  1070.  
  1071.         currentIndex = listboxEffects.SelectedIndex;
  1072.  
  1073.         // Make sure we don't update any settings while updating the UI
  1074.         isIgnoringSettings = true;
  1075.         UpdateUI(true);
  1076.         isIgnoringSettings = false;
  1077.     }
  1078.     private void UpdateUI(bool MoveControls)
  1079.     {
  1080.         ClearUI(MoveControls);
  1081.         
  1082.         Type    efftype = ((EffectInfo)effectDescription[currentIndex]).Effect.GetType();
  1083.         object  eff     = ((EffectInfo)effectDescription[currentIndex]).Effect;
  1084.  
  1085.         if (typeof(ChorusEffect) == efftype)
  1086.         {
  1087.             EffectsChorus temp = ((ChorusEffect)eff).AllParameters;
  1088.  
  1089.             if (MoveControls)
  1090.             {
  1091.                 trackbarSlider1.Minimum = (int)ChorusEffect.WetDryMixMin;
  1092.                 trackbarSlider1.Maximum = (int)ChorusEffect.WetDryMixMax;
  1093.                 trackbarSlider1.Value = (int)temp.WetDryMix;
  1094.                 trackbarSlider2.Minimum = (int)ChorusEffect.DepthMin;
  1095.                 trackbarSlider2.Maximum = (int)ChorusEffect.DepthMax;
  1096.                 trackbarSlider2.Value = (int)temp.Depth;
  1097.                 trackbarSlider3.Minimum = (int)ChorusEffect.FeedbackMin;
  1098.                 trackbarSlider3.Maximum = (int)ChorusEffect.FeedbackMax;
  1099.                 trackbarSlider3.Value = (int)temp.Feedback;
  1100.                 trackbarSlider4.Minimum = (int)ChorusEffect.FrequencyMin;
  1101.                 trackbarSlider4.Maximum = (int)ChorusEffect.FrequencyMax;
  1102.                 trackbarSlider4.Value = (int)temp.Frequency;
  1103.                 trackbarSlider5.Minimum = (int)ChorusEffect.DelayMin;
  1104.                 trackbarSlider5.Maximum = (int)ChorusEffect.DelayMax;
  1105.                 trackbarSlider5.Value = (int)temp.Delay;
  1106.  
  1107.                 if (ChorusEffect.WaveSin == temp.Waveform)
  1108.                     radiobuttonRadioSine.Checked = true;
  1109.                 else
  1110.                     radiobuttonTriangle.Checked = true;
  1111.  
  1112.                 if (ChorusEffect.PhaseNegative180 == temp.Phase)
  1113.                     radiobuttonRadioNeg180.Checked = true;
  1114.                 else if (ChorusEffect.PhaseNegative90 == temp.Phase)
  1115.                     radiobuttonRadioNeg90.Checked = true;
  1116.                 else if (ChorusEffect.PhaseZero == temp.Phase)
  1117.                     radiobuttonRadioZero.Checked = true;
  1118.                 else if (ChorusEffect.Phase90 == temp.Phase)
  1119.                     radiobuttonRadio90.Checked = true;
  1120.                 else if (ChorusEffect.Phase180 == temp.Phase)
  1121.                     radiobuttonRadio180.Checked = true;
  1122.  
  1123.                 groupboxFramePhase.Enabled = radiobuttonRadioNeg180.Enabled = radiobuttonRadioNeg90.Enabled = 
  1124.                 radiobuttonRadioZero.Enabled = radiobuttonRadio90.Enabled = radiobuttonRadio180.Enabled = 
  1125.                 groupboxFrameWaveform.Enabled = radiobuttonRadioSine.Enabled = 
  1126.                 radiobuttonTriangle.Enabled = true;
  1127.  
  1128.                 trackbarSlider1.Enabled = trackbarSlider2.Enabled = trackbarSlider3.Enabled = 
  1129.                 trackbarSlider4.Enabled = trackbarSlider5.Enabled = true;
  1130.             }
  1131.             labelParamValue1.Text = temp.WetDryMix.ToString();
  1132.             labelParamName1.Text = "Wet/Dry Mix (%)";
  1133.             
  1134.             labelParamValue2.Text =  temp.Depth.ToString();
  1135.             labelParamName2.Text = "Depth (%)";
  1136.  
  1137.             labelParamValue3.Text = temp.Feedback.ToString();
  1138.             labelParamName3.Text = "Feedback (%)";
  1139.  
  1140.             labelParamValue4.Text = temp.Frequency.ToString();
  1141.             labelParamName4.Text = "Frequency (Hz)";
  1142.  
  1143.             labelParamValue5.Text = temp.Delay.ToString();
  1144.             labelParamName5.Text = "Delay (ms)" ;
  1145.         }
  1146.         else if (typeof(CompressorEffect) == efftype)
  1147.         {
  1148.             EffectsCompressor temp = ((CompressorEffect)eff).AllParameters;
  1149.             
  1150.             if (MoveControls)
  1151.             {
  1152.                 trackbarSlider1.Minimum = (int)CompressorEffect.GainMin;
  1153.                 trackbarSlider1.Maximum = (int)CompressorEffect.GainMax;
  1154.                 trackbarSlider1.Value = (int)temp.Gain;
  1155.                 trackbarSlider2.Minimum = (int)CompressorEffect.AttackMin;
  1156.                 trackbarSlider2.Maximum = (int)CompressorEffect.AttackMax;
  1157.                 trackbarSlider2.Value = (int)temp.Attack;
  1158.                 trackbarSlider3.Minimum = (int)CompressorEffect.ReleaseMin;
  1159.                 trackbarSlider3.Maximum = (int)CompressorEffect.ReleaseMax;
  1160.                 trackbarSlider3.Value = (int)temp.Release;
  1161.                 trackbarSlider4.Minimum = (int)CompressorEffect.ThresholdMin;
  1162.                 trackbarSlider4.Maximum = (int)CompressorEffect.ThresholdMax;
  1163.                 trackbarSlider4.Value = (int)temp.Threshold;
  1164.                 trackbarSlider5.Minimum = (int)CompressorEffect.RatioMin;
  1165.                 trackbarSlider5.Maximum = (int)CompressorEffect.RatioMax;
  1166.                 trackbarSlider5.Value = (int)temp.Ratio;
  1167.                 trackbarSlider6.Minimum = (int)CompressorEffect.PreDelayMin;
  1168.                 trackbarSlider6.Maximum = (int)CompressorEffect.PreDelayMax;
  1169.                 trackbarSlider6.Value = (int)temp.Predelay;
  1170.  
  1171.                 trackbarSlider1.Enabled = trackbarSlider2.Enabled = trackbarSlider3.Enabled = 
  1172.                     trackbarSlider4.Enabled = trackbarSlider5.Enabled = trackbarSlider6.Enabled = true;
  1173.             }
  1174.             labelParamValue1.Text = temp.Gain.ToString();
  1175.             labelParamName1.Text = "Gain (dB)";
  1176.  
  1177.             labelParamName2.Text = "Attack (ms)";
  1178.             labelParamValue2.Text = temp.Attack.ToString();
  1179.             
  1180.             labelParamName3.Text = "Release (ms)";
  1181.             labelParamValue3.Text = temp.Release.ToString();
  1182.             
  1183.             labelParamName4.Text = "Threshold (dB)";
  1184.             labelParamValue4.Text = temp.Threshold.ToString();
  1185.             
  1186.             labelParamName5.Text = "Ratio (x:1)";
  1187.             labelParamValue5.Text = temp.Ratio.ToString();
  1188.             
  1189.             labelParamName6.Text = "Predelay (ms)";
  1190.             labelParamValue6.Text = temp.Predelay.ToString();
  1191.         }
  1192.         else if (typeof(DistortionEffect) == efftype)
  1193.         {
  1194.             EffectsDistortion temp = ((DistortionEffect)eff).AllParameters;
  1195.             
  1196.             if (MoveControls)
  1197.             {
  1198.                 trackbarSlider1.Minimum = (int)DistortionEffect.GainMin;
  1199.                 trackbarSlider1.Maximum = (int)DistortionEffect.GainMax;
  1200.                 trackbarSlider1.Value = (int)temp.Gain;
  1201.                 trackbarSlider2.Minimum = (int)DistortionEffect.EdgeMin;
  1202.                 trackbarSlider2.Maximum = (int)DistortionEffect.EdgeMax;
  1203.                 trackbarSlider2.Value = (int)temp.Edge;
  1204.                 trackbarSlider3.Minimum = (int)DistortionEffect.PostEqCenterFrequencyMin;
  1205.                 trackbarSlider3.Maximum = (int)DistortionEffect.PostEqCenterFrequencyMax;
  1206.                 trackbarSlider3.Value = (int)temp.PostEqCenterFrequency;
  1207.                 trackbarSlider4.Minimum = (int)DistortionEffect.PostEqBandwidthMin;
  1208.                 trackbarSlider4.Maximum = (int)DistortionEffect.PostEqBandwidthMax;
  1209.                 trackbarSlider4.Value = (int)temp.PostEqBandwidth;
  1210.                 trackbarSlider5.Minimum = (int)DistortionEffect.PreLowPassCutoffMin;
  1211.                 trackbarSlider5.Maximum = (int)DistortionEffect.PreLowPassCutoffMax;
  1212.                 trackbarSlider5.Value = (int)temp.PreLowpassCutoff;
  1213.  
  1214.                 trackbarSlider1.Enabled = trackbarSlider2.Enabled = trackbarSlider3.Enabled = 
  1215.                     trackbarSlider4.Enabled = trackbarSlider5.Enabled = true;
  1216.             }
  1217.             labelParamName1.Text = "Gain (dB)";
  1218.             labelParamValue1.Text = temp.Gain.ToString();
  1219.             
  1220.             labelParamName2.Text = "Edge (%)";
  1221.             labelParamValue2.Text = temp.Edge.ToString();
  1222.             
  1223.             labelParamName3.Text = "PostEQ Center Freq (Hz)";
  1224.             labelParamValue3.Text = temp.PostEqCenterFrequency.ToString();
  1225.             
  1226.             labelParamName4.Text = "PostEQ Bandwidth (Hz)";
  1227.             labelParamValue4.Text = temp.PostEqBandwidth.ToString();
  1228.             
  1229.             labelParamName5.Text = "PreLowpass Cutoff (Hz)";
  1230.             labelParamValue5.Text = temp.PreLowpassCutoff.ToString();
  1231.         }
  1232.         else if (typeof(EchoEffect) == efftype)
  1233.         {
  1234.             EffectsEcho temp = ((EchoEffect)eff).AllParameters;
  1235.             
  1236.             if (MoveControls)
  1237.             {
  1238.                 trackbarSlider1.Minimum = (int)EchoEffect.WetDryMixMin;
  1239.                 trackbarSlider1.Maximum = (int)EchoEffect.WetDryMixMax;
  1240.                 trackbarSlider1.Value = (int)temp.WetDryMix;
  1241.                 trackbarSlider2.Minimum = (int)EchoEffect.FeedbackMin;
  1242.                 trackbarSlider2.Maximum = (int)EchoEffect.FeedbackMax;
  1243.                 trackbarSlider2.Value = (int)temp.Feedback;
  1244.                 trackbarSlider3.Minimum = (int)EchoEffect.LeftDelayMin;
  1245.                 trackbarSlider3.Maximum = (int)EchoEffect.LeftDelayMax;
  1246.                 trackbarSlider3.Value = (int)temp.LeftDelay;
  1247.                 trackbarSlider4.Minimum = (int)EchoEffect.RightDelayMin;
  1248.                 trackbarSlider4.Maximum = (int)EchoEffect.RightDelayMax;
  1249.                 trackbarSlider4.Value = (int)temp.RightDelay;
  1250.                 trackbarSlider5.Minimum = EchoEffect.PanDelayMin;
  1251.                 trackbarSlider5.Maximum = EchoEffect.PanDelayMax;
  1252.                 trackbarSlider5.Value = temp.PanDelay;
  1253.  
  1254.                 trackbarSlider1.Enabled = trackbarSlider2.Enabled = trackbarSlider3.Enabled = 
  1255.                 trackbarSlider4.Enabled = trackbarSlider5.Enabled = true;
  1256.             }
  1257.             labelParamName1.Text = "Wet/Dry Mix (%)";
  1258.             labelParamValue1.Text = temp.WetDryMix.ToString();
  1259.             
  1260.             labelParamName2.Text = "Feedback (%)";
  1261.             labelParamValue2.Text = temp.Feedback.ToString();
  1262.             
  1263.             labelParamName3.Text = "Left Delay (ms)";           
  1264.             labelParamValue3.Text = temp.LeftDelay.ToString();
  1265.                         
  1266.             labelParamName4.Text = "Right Delay (ms)";
  1267.             labelParamValue4.Text = temp.RightDelay.ToString();
  1268.             
  1269.             labelParamName5.Text = "Pan Delay (bool)";
  1270.             labelParamValue5.Text = temp.PanDelay.ToString();
  1271.         }
  1272.         else if (typeof(FlangerEffect) == efftype)
  1273.         {
  1274.             EffectsFlanger temp = ((FlangerEffect)eff).AllParameters;
  1275.             
  1276.             if (MoveControls)
  1277.             {
  1278.                 trackbarSlider1.Minimum = (int)FlangerEffect.WetDryMixMin;
  1279.                 trackbarSlider1.Maximum = (int)FlangerEffect.WetDryMixMax;
  1280.                 trackbarSlider1.Value = (int)temp.WetDryMix;
  1281.                 trackbarSlider2.Minimum = (int)FlangerEffect.DepthMin;
  1282.                 trackbarSlider2.Maximum = (int)FlangerEffect.DepthMax;
  1283.                 trackbarSlider2.Value = (int)temp.Depth;
  1284.                 trackbarSlider3.Minimum = (int)FlangerEffect.FeedbackMin;
  1285.                 trackbarSlider3.Maximum = (int)FlangerEffect.FeedbackMax;
  1286.                 trackbarSlider3.Value = (int)temp.Feedback;
  1287.                 trackbarSlider4.Minimum = (int)FlangerEffect.FrequencyMin;
  1288.                 trackbarSlider4.Maximum = (int)FlangerEffect.FrequencyMax;
  1289.                 trackbarSlider4.Value = (int)temp.Frequency;
  1290.                 trackbarSlider5.Minimum = (int)FlangerEffect.DelayMin;
  1291.                 trackbarSlider5.Maximum = (int)FlangerEffect.DelayMax;
  1292.                 trackbarSlider5.Value = (int)temp.Delay;
  1293.  
  1294.                 if (ChorusEffect.WaveSin == temp.Waveform)
  1295.                     radiobuttonRadioSine.Checked = true;
  1296.                 else
  1297.                     radiobuttonTriangle.Checked = true;
  1298.             
  1299.                 if (FlangerEffect.PhaseNeg180 == temp.Phase)
  1300.                     radiobuttonRadioNeg180.Checked = true;
  1301.                 else if (FlangerEffect.PhaseNeg90 == temp.Phase)
  1302.                     radiobuttonRadioNeg90.Checked = true;
  1303.                 else if (FlangerEffect.PhaseZero == temp.Phase)
  1304.                     radiobuttonRadioZero.Checked = true;
  1305.                 else if (FlangerEffect.Phase90 == temp.Phase)
  1306.                     radiobuttonRadio90.Checked = true;
  1307.                 else if (FlangerEffect.Phase180 == temp.Phase)
  1308.                     radiobuttonRadio180.Checked = true;
  1309.  
  1310.                 groupboxFramePhase.Enabled = radiobuttonRadioNeg180.Enabled = radiobuttonRadioNeg90.Enabled = 
  1311.                 radiobuttonRadioZero.Enabled = radiobuttonRadio90.Enabled = radiobuttonRadio180.Enabled = 
  1312.                 groupboxFrameWaveform.Enabled = radiobuttonRadioSine.Enabled = radiobuttonTriangle.Enabled = true;
  1313.  
  1314.                 trackbarSlider1.Enabled = trackbarSlider2.Enabled = trackbarSlider3.Enabled = 
  1315.                 trackbarSlider4.Enabled = trackbarSlider5.Enabled = true;
  1316.             }
  1317.             labelParamName1.Text = "Wet/Dry Mix (%)";
  1318.             labelParamValue1.Text = temp.WetDryMix.ToString();
  1319.             
  1320.             labelParamName2.Text = "Depth (%)";
  1321.             labelParamValue2.Text = temp.Depth.ToString();
  1322.             
  1323.             labelParamName3.Text = "Feedback (%)";
  1324.             labelParamValue3.Text = temp.Feedback.ToString();
  1325.             
  1326.             labelParamName4.Text = "Frequency (Hz)";
  1327.             labelParamValue4.Text = temp.Frequency.ToString();
  1328.             
  1329.             labelParamName5.Text = "Delay (ms)";
  1330.             labelParamValue5.Text = temp.Delay.ToString();          
  1331.         }
  1332.         else if (typeof(GargleEffect) == efftype)
  1333.         {
  1334.             EffectsGargle temp = ((GargleEffect)eff).AllParameters;
  1335.             
  1336.             if (MoveControls)
  1337.             {
  1338.                 trackbarSlider1.Minimum = GargleEffect.RateHzMin;
  1339.                 trackbarSlider1.Maximum = GargleEffect.RateHzMax;
  1340.                 trackbarSlider1.Value = temp.RateHz;
  1341.  
  1342.                 if (GargleEffect.WaveSquare == temp.WaveShape)
  1343.                     radiobuttonSquare.Checked = true;
  1344.                 else
  1345.                     radiobuttonTriangle.Checked = true;
  1346.  
  1347.                 groupboxFrameWaveform.Enabled = radiobuttonSquare.Enabled = radiobuttonTriangle.Enabled = true;
  1348.  
  1349.                 trackbarSlider1.Enabled = true;
  1350.             }
  1351.             labelParamName1.Text = "Rate (Hz)";
  1352.             labelParamValue1.Text = temp.RateHz.ToString();     
  1353.         }
  1354.         else if (typeof(ParamEqEffect) == efftype)
  1355.         {
  1356.             EffectsParamEq temp = ((ParamEqEffect)eff).AllParameters;
  1357.             
  1358.             if (MoveControls)
  1359.             {
  1360.                 trackbarSlider1.Minimum = (int)ParamEqEffect.CenterMin;
  1361.                 trackbarSlider1.Maximum = (int)ParamEqEffect.CenterMax;
  1362.                 trackbarSlider1.Value = (int)temp.Center;
  1363.                 trackbarSlider2.Minimum = (int)ParamEqEffect.BandwidthMin;
  1364.                 trackbarSlider2.Maximum = (int)ParamEqEffect.BandwidthMax;
  1365.                 trackbarSlider2.Value = (int)temp.Bandwidth;
  1366.                 trackbarSlider3.Minimum = (int)ParamEqEffect.GainMin;
  1367.                 trackbarSlider3.Maximum = (int)ParamEqEffect.GainMax;
  1368.                 trackbarSlider3.Value = (int)temp.Gain;
  1369.  
  1370.                 trackbarSlider1.Enabled = trackbarSlider2.Enabled = trackbarSlider3.Enabled = true;
  1371.             }
  1372.             labelParamName1.Text = "Center Freq (Hz)";
  1373.             labelParamValue1.Text = temp.Center.ToString();
  1374.             
  1375.             labelParamName2.Text = "Bandwidth (Hz)";
  1376.             labelParamValue2.Text = temp.Bandwidth.ToString();
  1377.             
  1378.             labelParamName3.Text = "Gain (dB)";
  1379.             labelParamValue3.Text = temp.Gain.ToString();
  1380.         }
  1381.         else if (typeof(WavesReverbEffect) == efftype)
  1382.         {
  1383.             EffectsWavesReverb temp = ((WavesReverbEffect)eff).AllParameters;
  1384.             
  1385.             if (MoveControls)
  1386.             {
  1387.                 trackbarSlider1.Minimum = (int)WavesReverbEffect.InGainMin;
  1388.                 trackbarSlider1.Maximum = (int)WavesReverbEffect.InGainMax;
  1389.                 trackbarSlider1.Value = (int)temp.InGain;
  1390.                 trackbarSlider2.Minimum = (int)WavesReverbEffect.ReverbMixMin;
  1391.                 trackbarSlider2.Maximum = (int)WavesReverbEffect.ReverbMixMax;
  1392.                 trackbarSlider2.Value = (int)temp.ReverbMix;
  1393.                 trackbarSlider3.Minimum = (int)(1000 * WavesReverbEffect.ReverbTimeMin);
  1394.                 trackbarSlider3.Maximum = (int)(1000 * WavesReverbEffect.ReverbTimeMax);
  1395.                 trackbarSlider3.Value = (int)(1000 * temp.ReverbTime);
  1396.                 trackbarSlider4.Minimum = (int)(1000 * WavesReverbEffect.HighFrequencyRtRatioMin);
  1397.                 trackbarSlider4.Maximum = (int)(1000 * WavesReverbEffect.HighFrequencyRtRatioMax);
  1398.                 trackbarSlider4.Value = (int)(1000 * temp.HighFrequencyRtRatio);
  1399.  
  1400.                 trackbarSlider1.Enabled = trackbarSlider2.Enabled = trackbarSlider3.Enabled = trackbarSlider4.Enabled = true;
  1401.             }
  1402.             labelParamName1.Text = "In Gain (dB)";
  1403.             labelParamValue1.Text = temp.InGain.ToString();
  1404.             
  1405.             labelParamName2.Text = "Waves Reverb Mix (dB)";
  1406.             labelParamValue2.Text = temp.ReverbMix.ToString();
  1407.             
  1408.             labelParamName3.Text = "Waves Reverb Time (ms)";
  1409.             labelParamValue3.Text = temp.ReverbTime.ToString();
  1410.             
  1411.             labelParamName4.Text = "HighFreq RT Ratio (x:1)";
  1412.             labelParamValue4.Text = temp.HighFrequencyRtRatio.ToString();
  1413.         }
  1414.     }
  1415.     private void ClearUI(bool ClearControls)
  1416.     {
  1417.         labelParamName1.Text = labelParamValue1.Text = labelParamName2.Text = labelParamValue2.Text =  
  1418.         labelParamName3.Text = labelParamValue3.Text = labelParamName4.Text = labelParamValue4.Text =
  1419.         labelParamName5.Text = labelParamValue5.Text = labelParamName6.Text = labelParamName1.Text = 
  1420.         labelParamValue1.Text = labelParamName2.Text = labelParamValue2.Text = labelParamName3.Text = 
  1421.         labelParamValue3.Text = labelParamName4.Text = labelParamValue4.Text = labelParamName5.Text = 
  1422.         labelParamValue5.Text =labelParamName6.Text = labelParamValue6.Text = labelParamName1.Text = 
  1423.         labelParamValue1.Text = labelParamName2.Text = labelParamValue2.Text = labelParamName3.Text = 
  1424.         labelParamValue3.Text = labelParamName4.Text = labelParamValue4.Text = labelParamName5.Text = 
  1425.         labelParamValue5.Text = labelParamName6.Text = labelParamName1.Text = labelParamValue1.Text =
  1426.         labelParamName2.Text = labelParamValue2.Text = labelParamName3.Text = labelParamValue3.Text =
  1427.         labelParamName4.Text = labelParamValue4.Text = labelParamName5.Text = labelParamValue5.Text =
  1428.         labelParamName6.Text = labelParamName1.Text = labelParamValue1.Text = labelParamName2.Text = 
  1429.         labelParamValue2.Text = labelParamName3.Text = labelParamValue3.Text = labelParamName4.Text = 
  1430.         labelParamValue4.Text = labelParamName5.Text = labelParamValue5.Text = labelParamName6.Text =       
  1431.         labelParamName1.Text = labelParamValue1.Text = labelParamName2.Text = labelParamValue2.Text =
  1432.         labelParamName3.Text = labelParamName4.Text = labelParamValue4.Text = labelParamName5.Text = 
  1433.         labelParamValue5.Text = labelParamName6.Text = labelParamValue6.Text = labelParamName1.Text = 
  1434.         labelParamValue1.Text = labelParamName2.Text = labelParamValue2.Text = labelParamName3.Text = 
  1435.         labelParamValue3.Text = labelParamName4.Text = labelParamValue4.Text = labelParamName5.Text = 
  1436.         labelParamValue5.Text = labelParamName6.Text = labelParamValue6.Text = labelParamName1.Text = 
  1437.         labelParamValue1.Text = labelParamName2.Text = labelParamValue2.Text = labelParamName3.Text = 
  1438.         labelParamValue3.Text = labelParamName4.Text = labelParamValue4.Text = labelParamName5.Text = 
  1439.         labelParamValue5.Text = labelParamName6.Text = labelParamValue6.Text = string.Empty;
  1440.  
  1441.         if (ClearControls)
  1442.         {
  1443.             groupboxFrameWaveform.Enabled = radiobuttonTriangle.Enabled = radiobuttonTriangle.Enabled = radiobuttonRadioSine.Enabled =
  1444.             groupboxFramePhase.Enabled = radiobuttonRadioNeg180.Enabled = radiobuttonRadioNeg90.Enabled = radiobuttonRadioZero.Enabled =
  1445.             radiobuttonRadio90.Enabled = radiobuttonRadio180.Enabled = false;
  1446.  
  1447.             trackbarSlider1.Minimum = trackbarSlider2.Minimum = trackbarSlider3.Minimum = 
  1448.             trackbarSlider4.Minimum = trackbarSlider5.Minimum = trackbarSlider6.Minimum = 0;
  1449.             trackbarSlider1.Value = trackbarSlider2.Value = trackbarSlider3.Value = 
  1450.             trackbarSlider4.Value = trackbarSlider5.Value = trackbarSlider6.Value = 0;
  1451.             trackbarSlider1.Enabled = trackbarSlider2.Enabled = trackbarSlider3.Enabled = 
  1452.             trackbarSlider4.Enabled = trackbarSlider5.Enabled = trackbarSlider6.Enabled = false;
  1453.         }
  1454.     }
  1455.  
  1456.     private void trackbarSliderScroll(object sender, System.EventArgs e)
  1457.     {
  1458.         // We're ignoring settings right now
  1459.         if (isIgnoringSettings)
  1460.             return;
  1461.  
  1462.         EffectInfo eff = (EffectInfo)effectDescription[currentIndex];
  1463.         Type efftype = eff.Effect.GetType();
  1464.  
  1465.         if (typeof(ChorusEffect) == efftype)
  1466.         {
  1467.             EffectsChorus temp = new EffectsChorus();
  1468.             temp.WetDryMix = trackbarSlider1.Value;
  1469.             temp.Frequency = trackbarSlider4.Value;
  1470.             temp.Feedback = trackbarSlider3.Value;
  1471.             temp.Depth = trackbarSlider2.Value;
  1472.             temp.Delay = trackbarSlider5.Value;
  1473.             
  1474.             if (true == radiobuttonRadioSine.Checked)
  1475.                 temp.Waveform = ChorusEffect.WaveSin;
  1476.             else
  1477.                 temp.Waveform = ChorusEffect.WaveTriangle;
  1478.             
  1479.             if (true == radiobuttonRadioNeg180.Checked)
  1480.                 temp.Phase = ChorusEffect.PhaseNegative180;
  1481.             else if (true == radiobuttonRadioNeg90.Checked)
  1482.                 temp.Phase = ChorusEffect.PhaseNegative90;
  1483.             else if (true == radiobuttonRadioZero.Checked)
  1484.                 temp.Phase = ChorusEffect.PhaseZero;
  1485.             else if (true == radiobuttonRadio90.Checked)
  1486.                 temp.Phase = ChorusEffect.Phase90;
  1487.             else if (true == radiobuttonRadio180.Checked)
  1488.                 temp.Phase = ChorusEffect.Phase180;
  1489.  
  1490.             eff.EffectSettings = temp;
  1491.             ((ChorusEffect)eff.Effect).AllParameters = temp;            
  1492.         }
  1493.         else if (typeof(CompressorEffect) == efftype)
  1494.         {
  1495.             EffectsCompressor temp = new EffectsCompressor();
  1496.             temp.Gain = trackbarSlider1.Value;
  1497.             temp.Attack = trackbarSlider2.Value;
  1498.             temp.Release = trackbarSlider3.Value;
  1499.             temp.Threshold = trackbarSlider4.Value;
  1500.             temp.Ratio = trackbarSlider5.Value;
  1501.             temp.Predelay = trackbarSlider6.Value;
  1502.  
  1503.             eff.EffectSettings = temp;
  1504.             ((CompressorEffect)eff.Effect).AllParameters = temp;
  1505.         }
  1506.         else if (typeof(DistortionEffect) == efftype)
  1507.         {
  1508.             EffectsDistortion temp = new EffectsDistortion();
  1509.             temp.Gain = trackbarSlider1.Value;
  1510.             temp.Edge = trackbarSlider2.Value;
  1511.             temp.PostEqCenterFrequency = trackbarSlider3.Value;
  1512.             temp.PostEqBandwidth = trackbarSlider4.Value;
  1513.             temp.PreLowpassCutoff = trackbarSlider5.Value;
  1514.  
  1515.             eff.EffectSettings = temp;
  1516.             ((DistortionEffect)eff.Effect).AllParameters = temp;
  1517.         }
  1518.         else if (typeof(EchoEffect) == efftype)
  1519.         {
  1520.             EffectsEcho temp = new EffectsEcho();
  1521.             temp.WetDryMix = trackbarSlider1.Value;
  1522.             temp.Feedback = trackbarSlider2.Value;
  1523.             temp.LeftDelay = trackbarSlider3.Value;
  1524.             temp.RightDelay = trackbarSlider4.Value;
  1525.             temp.PanDelay = trackbarSlider5.Value;
  1526.  
  1527.             eff.EffectSettings = temp;
  1528.             ((EchoEffect)eff.Effect).AllParameters = temp;
  1529.         }
  1530.         else if (typeof(FlangerEffect) == efftype)
  1531.         {
  1532.             EffectsFlanger temp = new EffectsFlanger();
  1533.             temp.WetDryMix = trackbarSlider1.Value;
  1534.             temp.Depth = trackbarSlider2.Value;
  1535.             temp.Feedback = trackbarSlider3.Value;
  1536.             temp.Frequency = trackbarSlider4.Value;
  1537.             temp.Delay = trackbarSlider5.Value;
  1538.         
  1539.             if (true == radiobuttonRadioSine.Checked)
  1540.                 temp.Waveform = FlangerEffect.WaveSin;
  1541.             else
  1542.                 temp.Waveform = FlangerEffect.WaveTriangle;
  1543.  
  1544.             if (true == radiobuttonRadioNeg180.Checked)
  1545.                 temp.Phase = ChorusEffect.PhaseNegative180;
  1546.             else if (true == radiobuttonRadioNeg90.Checked)
  1547.                 temp.Phase = ChorusEffect.PhaseNegative90;
  1548.             else if (true == radiobuttonRadioZero.Checked)
  1549.                 temp.Phase = ChorusEffect.PhaseZero;
  1550.             else if (true == radiobuttonRadio90.Checked)
  1551.                 temp.Phase = ChorusEffect.Phase90;
  1552.             else if (true == radiobuttonRadio180.Checked)
  1553.                 temp.Phase = ChorusEffect.Phase180;
  1554.  
  1555.             eff.EffectSettings = temp;
  1556.             ((FlangerEffect)eff.Effect).AllParameters = temp;
  1557.         }
  1558.         else if (typeof(GargleEffect) == efftype)
  1559.         {
  1560.             EffectsGargle temp = new EffectsGargle();
  1561.             temp.RateHz = trackbarSlider1.Value;
  1562.             if (radiobuttonSquare.Checked)
  1563.                 temp.WaveShape = GargleEffect.WaveSquare;
  1564.             else
  1565.                 temp.WaveShape = GargleEffect.WaveTriangle;
  1566.  
  1567.             if (true == radiobuttonSquare.Checked)
  1568.                 temp.WaveShape = GargleEffect.WaveSquare;
  1569.             else
  1570.                 temp.WaveShape = GargleEffect.WaveTriangle;
  1571.  
  1572.             eff.EffectSettings = temp;
  1573.             ((GargleEffect)eff.Effect).AllParameters = temp;
  1574.         }
  1575.         else if (typeof(ParamEqEffect) == efftype)
  1576.         {
  1577.             EffectsParamEq temp = new EffectsParamEq();
  1578.             temp.Center = trackbarSlider1.Value;
  1579.             temp.Bandwidth = trackbarSlider2.Value;
  1580.             temp.Gain = trackbarSlider3.Value;
  1581.  
  1582.             eff.EffectSettings = temp;
  1583.             ((ParamEqEffect)eff.Effect).AllParameters = temp;
  1584.         }
  1585.         else if (typeof(WavesReverbEffect) == efftype)
  1586.         {
  1587.             EffectsWavesReverb temp = new EffectsWavesReverb();
  1588.             temp.InGain = trackbarSlider1.Value;
  1589.             temp.ReverbMix = trackbarSlider2.Value;
  1590.             temp.ReverbTime = (float)(.001 * trackbarSlider3.Value);
  1591.             temp.HighFrequencyRtRatio = (float)(.001 * trackbarSlider4.Value);
  1592.  
  1593.             eff.EffectSettings = temp;
  1594.             ((WavesReverbEffect)eff.Effect).AllParameters = temp;
  1595.         }       
  1596.         effectDescription[currentIndex] = eff;
  1597.         UpdateUI(false);
  1598.     }
  1599.  
  1600.     private void DeleteEffect()
  1601.     {
  1602.         EffectInfo[] temp = null;
  1603.  
  1604.         if (-1 == listboxEffects.SelectedIndex) 
  1605.             return;
  1606.  
  1607.         effectDescription.RemoveAt(listboxEffects.SelectedIndex);
  1608.  
  1609.         if (effectDescription.Count > 0)
  1610.         {
  1611.             temp = new EffectInfo[effectDescription.Count];
  1612.             effectDescription.CopyTo(temp, 0);
  1613.             AddEffect(temp);
  1614.             listboxEffects.Items.RemoveAt(listboxEffects.SelectedIndex);                
  1615.             listboxEffects.SelectedIndex = currentIndex = 0;
  1616.         }
  1617.         else
  1618.         {
  1619.             temp = null;
  1620.             AddEffect(temp);
  1621.             listboxEffects.Items.Clear();
  1622.             ClearUI(true);
  1623.         }
  1624.         effectDescription.Clear();
  1625.         if (null != temp)
  1626.             effectDescription.AddRange(temp);        
  1627.     }
  1628.  
  1629.     private void listboxEffects_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
  1630.     {
  1631.         if (e.KeyCode == Keys.Delete)
  1632.             DeleteEffect();
  1633.     }
  1634.  
  1635.     private void buttonOk_Click(object sender, System.EventArgs e)
  1636.     {
  1637.         this.Close();
  1638.     }
  1639.  
  1640.     private void buttonDelete_Click(object sender, System.EventArgs e)
  1641.     {
  1642.         DeleteEffect();
  1643.     }
  1644.  
  1645.     private void timer1_Tick(object sender, System.EventArgs e)
  1646.     {
  1647.         if(applicationBuffer.Status.Playing)
  1648.             return;
  1649.         else
  1650.         {
  1651.             timer1.Enabled = false;
  1652.             buttonStop.Enabled = false;
  1653.             buttonPlay.Enabled = true;
  1654.             comboEffects.Enabled = true;
  1655.  
  1656.             labelTextStatus.Text="Sound stopped.";
  1657.         }    
  1658.     }
  1659.  
  1660.     private void MainForm_Closing(object sender, System.ComponentModel.CancelEventArgs e)
  1661.     {
  1662.         if (null != applicationBuffer)
  1663.         {
  1664.             if(applicationBuffer.Status.Playing)
  1665.                 applicationBuffer.Stop();
  1666.         }
  1667.     }
  1668. }
  1669.